using System.IO;
using UnityEditor;
using UnityEngine;

public class BuildBundles : Editor
{
    [MenuItem("Custom/BuildBundle")]
    private static void BuildBundle()
    {
        string outputPath = Path.Combine(Application.streamingAssetsPath, "AssetBundle");
        Debug.Log($"outputPath = {outputPath}");
        // 删除旧的AssetBundle
        new DirectoryInfo(outputPath).Delete(true);
        if (!Directory.Exists(outputPath))
        {
            Debug.Log("not exist");
            Directory.CreateDirectory(outputPath);
        }
        // BuildTarget根据需要做调整
        BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows64);
        
        AssetDatabase.Refresh();
    }
}
